package com.example.controller;


import com.example.pojo.*;
import com.example.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/emps")
public class EmpController {
    @Autowired
    private EmpService empService;

    //分页查询
    @GetMapping
    public Result page(EmpQueryParam param){
        log.info("{}",param);
        PageResult<Emp> pageResult = empService.page(param);
        return Result.success(pageResult);
    }
    //添加员工
    @PostMapping

    public Result save(@RequestBody Emp emp){
        log.info("{}",emp);
        empService.save(emp);
        return Result.success();
    }
    //查询全部员工
    @GetMapping("/list")
    public Result findAll() {
        List<Emp> list = empService.findAll();
        return Result.success(list);
    }
    //根据id查询员工
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id) {
        Emp emp = empService.findById(id);
        return Result.success(emp);
    }
    //修改员工
    @PutMapping

    public Result update(@RequestBody Emp emp) {
        log.info("修改员工信息{}", emp);
        empService.update(emp);
        return Result.success();
    }
    //删除员工
    @DeleteMapping

    public Result delete(@RequestParam List<Integer> ids) {
        log.info("{}", ids);
        empService.batchDelete(ids);
        return Result.success();
    }

}
